
/**
 * @description  : 字典选择组件
 * @descriptionDetail : 字典选择组件
 * @copyright    : 浙江烟草
 * @author       : mc
 * @create       : 2022-10-03 17:08:55
 */
<template>
  <view style="width: 100%;">
    <u-input
      :border="border"
      type="select"
      :placeholder="$attrs.placeholder || '请选择'"
      v-model="value"
      v-bind="$attrs"
      @click="dictShow = !readOnly"
      :select-open="dictShow"
    ></u-input>
    <u-action-sheet :list="dictList" v-model="dictShow" @click="selectConfirm"></u-action-sheet>
  </view>
</template>
<script>
export default {
  props: {
    value: {
      type: String | Number,
      default: ''
    },
    dictType: {     // 字典类型
      type: String,
      default: ""
    },
    readOnly: { // 只读
     type: Boolean,
      default: false
    },
    questionTab:{
      type: String,
      default: null
    }
  },
  data() {
    return {
      border: false,
      dictShow: false,
      dictList: [],
      dicArr:[],
    }
  },
  watch: {
    questionTab:{
      handler(v){
        this.dictList=this.dicArr.filter(item=>item.parentBcbCode==v)
      },
    },
    dictType: {
      immediate: true,
      handler(v) {
        if(v=='I_INVEST_RESULT_NATURE'){
          this.dicArr=this.$u.dic.getByDictCode(v);
          this.dicArr.forEach(d => d.text = d.label);
        }
        this.dictList = this.$u.dic.getByDictCode(v);
        if(this.questionTab){
          let s=this.dictList.filter(item=>{
            if(item.parentBcbCode=='00'||item.parentBcbCode==this.questionTab){
              return item
            }
          })
          this.dictList=s;
        }
        this.dictList.forEach(d => d.text = d.label);
      },
    },
    value: {
      immediate: true,
      handler(v) {
        console.log("value", v);
      },
    }
  },
  created () {
  },
  methods: {
    selectConfirm(idx) {
      this.$emit("confirm", this.dictList[idx],this.dictList);
      this.$emit("input", this.dictList[idx].bcbName);

      this.dictShow = false;
    }
  },
}
</script>
